﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace WjAutoConfigApp
{
    /// <summary>
    /// 操作文件的方法
    /// </summary>
    public class FileMethod
    {
        /// <summary>
        /// 创建文件/创建并写入文件
        /// </summary>
        /// <param name="fullFileName"></param>
        /// <param name="content"></param>
        public static void WriteToFile(string fullFileName, bool isAppend = true,string content = null)
        {
            if (!File.Exists(fullFileName))
            {
                using (FileStream fs = new FileStream(fullFileName, FileMode.Create, FileAccess.Write))
                using (StreamWriter sw = new StreamWriter(fs))
                {
                    if (content is null)
                    {
                        return;
                    }
                    sw.WriteLine(content);
                    sw.Flush();
                }
            }
            else
            {
                using (StreamWriter sw = new StreamWriter(fullFileName, isAppend, Encoding.Default))
                {
                    if (content is null)
                    {
                        return;
                    }
                    sw.WriteLine(content);
                    sw.Flush();
                }
            }
        }
    }
}
